#ifndef hwboard_h
#define hwboard_h

#include <boardbase.h>
#include <core_debug.h>

#include "dbnc_flt.h"
#include <rte_data.h>
#include <plc_task.h>
#include <SimpleKalmanFilter.h>
#include <in_analog.h>
// #include "flashFs.h"

class hwboard : public boardBase {
public:
    hwboard();

    ~hwboard() override = default;

    int begin(uint32_t tick) override;

    int run(uint32_t tick) override;

    void ioled();

#ifndef THIS_IS_BOOTLOADER
#ifdef __PLATFORMIO_BUILD_DEBUG__
    int dev_test(uint32_t tick) override;
#endif

    int get_dbg_jmpr_get() override;

    int get_rst_jmpr_get() override;

    int Poll(uint32_t) override;

    void board_output(uint32_t tick) override;

    void plc_run_start() override;

    void plc_run_end() override;

    int test_hw() override;

#endif

    static void boot_mode_enter();

    static void plc_run_stop();

    static void plc_run_error();

    static void plc_run_empty();

    void led_run(int) override;

    void led_err(int) override;

    int type() {
        return pb_object_board_info_tag;
    }

    int encode(pb_object *object, pb_ostream_t *stream) override {
        object->object.board_info = data;
        object->which_object = pb_object_board_info_tag;
        return pb_encode(stream, pb_object_fields, object);
    }

    int iter(pb_field_iter_t *pS) override {
        return pb_field_iter_begin(pS, pb_board_info_fields, &data);
    }

    static PinName LED_RUN;
    static PinName LED_ERR;
    PinName LED_ETH = PC_3;
    u8 XA4 = PA3;

    u8 model{};

    void led(uint32_t tick) override;

    u8 plc_state = 0xff;
    bool digitalValue[(IO_YO_NRS + IO_XI_NRS)]{};
    u8 alarm = 0xff;
    u8 status = 0xff;
    uint32_t xa_ori[IO_XA_NRS];
    bool XCLEAR[IO_XI_NRS];
    float xa32[4];
    uint32_t XCOUNT[IO_XI_NRS];
    int32_t fil_param[14];
};

extern hwboard board;
#endif
